package com.bawei.day14_zuoye.adapter;

import android.content.ContentProvider;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawei.day14_zuoye.R;
import com.bawei.day14_zuoye.bean.SongBean;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;

import java.util.List;

public class SongAdapter extends BaseAdapter {
    private Context context;
    private List<SongBean> list;

    public SongAdapter(Context context, List<SongBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Viewholder viewholder = new Viewholder();
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item,null);
            viewholder.imageView = convertView.findViewById(R.id.iv);
            viewholder.iv_menu = convertView.findViewById(R.id.iv_menu);
            viewholder.textView = convertView.findViewById(R.id.tv_name);
            convertView.setTag(viewholder);
        }else{
            viewholder = (Viewholder) convertView.getTag();
        }
        viewholder.textView.setText(list.get(position).getName()+"");
        Glide.with(context)
                .load(list.get(position).getAlbum())
                .transform(new CircleCrop())
                .into(viewholder.imageView);





        return convertView;
    }
    class Viewholder{
        ImageView imageView,iv_menu;
        TextView textView;
    }
}
